<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>会员列表</title>
<meta name="description" content="这是一个 index 页面">
<meta name="keywords" content="index">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="icon" type="image/png" href="../assets/i/favicon.png">
<link rel="aFple-touch-icon-precomposed"
	href="../assets/i/app-icon72x72@2x.png">
<meta name="apple-mobile-web-app-title" content="Amaze UI" />
<link rel="stylesheet" href="../assets/css/amazeui.min.css" />
<link rel="stylesheet" href="../assets/css/admin.css">
<link href="../assets/js/layui/css/layui.css">

</head>
<body>
	<!--[if lte IE 9]><p class="browsehappy">升级你的浏览器吧！ <a href="http://se.360.cn/" target="_blank">升级浏览器</a>以获得更好的体验！</p>
<![endif]-->
</head>


<body>
	<div>
		<br>
		<h3 class="am-popup-title" align="center">修改用户</h3>

		<form class="am-form tjlanmu">

			<div class="am-form-group">
				<div class="you">
					<input type="text" id="name" class="am-input-sm"
						placeholder="请输入用户名称">
				</div>
			</div>
			<div class="am-form-group">
				<div class="zuo">用户名称：</div>
				<div class="you" style="margin-top: 9px;">
				<label class="am-checkbox-inline"> 
					<input type="radio" name="role" value="1">超级管理员</label>
					<label class="am-checkbox-inline"> 
					<input type="radio" name="role" value="2">经理</label>
					<label class="am-checkbox-inline"> 
					<input type="radio" name="role" value="3">员工</label>
				</div>
			</div>
			<div class="am-form-group am-cf">
				<div class="zuo">角色名称：</div>
			</div>
			<div class="am-form-group am-cf">
				<div class="zuo">用户账号：</div>
				<div class="you">
					<input type="text" id="adminCode" class="am-input-sm"
						placeholder="请输入用户账号">
				</div>
			</div>
			<div class="am-form-group am-cf">
				<div class="zuo">用户密码：</div>
				<div class="you">
					<input type="password" id="adminPassword" class="am-input-sm"
						placeholder="请输入用户用户密码">
				</div>
			</div>
			<div class="am-form-group am-cf">
				<div class="zuo">用户性别：</div>
				<div class="you" id="sex">
					<label class="am-checkbox-inline"> <input
						name="addAdmin_sex" type="radio" value="1"> 男
					</label> <label class="am-checkbox-inline"> <input
						name="addAdmin_sex" type="radio" value="2"> 女
					</label>
				</div>
			</div>

			<div class="am-form-group am-cf">
				<div class="zuo">手机号码：</div>
				<div class="you">
					<input type="text" id="phone" class="am-input-sm"
						placeholder="请输入用户手机号码">
				</div>
			</div>
			<div class="am-form-group am-cf">
				<div class="you">
					<p>
						<input type="button" id="createBy" value="提交"/>
					</p>
				</div>
			</div>
		</form>


	</div>

	<script type="text/javascript">
		
	$(function(){
		$.ajax({
			url:"/moviesMaven/admin/getAdmins.htm",
			data:{
				"id":id
				},
			dataType:"json",
			success:function(data){
				if(data.success){
					$("#name").val(data.result[0].adminName);
					$('input[name="role"][value='+data.result[0].roleId+']').prop("checked","true");
					$("#adminCode").val(data.result[0].adminCode);
					$("#adminPassword").val(data.result[0].adminPassword);
					$('#sex input[name="addAdmin_sex"][value='+data.result[0].sex+']').prop("checked","true");
					$("#phone").val(data.result[0].phone);
				}
			}
		})
	})
	
		
		var adminNames;
		var roleIds;
		var adminCodes;
		var adminPasswords;
		var sexs;
		var phones;
	
		//添加会员
		$("#createBy").click(function() {
			adminNames = $("#name").val();
			roleIds = $('input[name="role"]:checked').val();
			adminCodes = $("#adminCode").val();
			adminPasswords = $("#adminPassword").val();
			sexs = $('#sex input[name="addAdmin_sex"]:checked ').val();
			phones = $("#phone").val();
			
			if(adminNames==null||adminNames==""){
				layer.msg("用户名称不能为空")
			}else if(adminCodes==null||adminCodes==""){
				layer.msg("账号不能为空")
			}else if(adminPasswords==null||adminPasswords==""){
				layer.msg("密码不能为空")
			}else if(phones==null||phones==""){
				layer.msg("电话不能为空")
			}else if(roleIds==null||roleIds==""){
				layer.msg("角色名称不能为空")	
			}else{//确认是否修改
				$.ajax({
					url:"/moviesMaven/admin/getAdminCheck.htm",
					data:{
						"roleId" : roleIds,
						"adminCode" : adminCodes,
						"adminPassword" : adminPasswords,
						"adminName" : adminNames,
						"sex" : sexs,
						"phone" : phones
						},
					dataType:"json",
					success:function(data){
						if(data.success){
							login(adminNames,roleIds,adminCodes,adminPasswords,sexs,phones)
						}else{
							layer.msg("没有要修改的")
						}
					}
				})
			}
		})
		
			
		
		//添加
		function login(adminName,roleId,adminCode,adminPassword,sex,phone){
			$.ajax({
				url : "/moviesMaven/admin/updateAdmin.htm",
				data : {
					"id" : id,
					"roleId" : roleId,
					"adminCode" : adminCode,
					"adminPassword" : adminPassword,
					"adminName" : adminName,
					"sex" : sex,
					"phone" : phone
				},
				dataType : "json",
				success : function(data) {
					layer.msg('修改成功',{
						time:2000
					},function(){
						$("#admin").load("admin.html");
					})
				}
				
			})
		}
	</script>
</body>
</html>